﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using E_Shop.Common;
using ESHOP.DAO;
using ESHOP.Domain;
namespace E_Shop
{
    public partial class CompanyAcount : Authentication
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Loadreference();
            }
            BindataToForm();
           
        }

        private void BindataToForm()
        {
            ACOUNT _account = new AccountDAO().Get(Acount.USERNAME);
            txtFullName.Text = _account.FULLNAME==null?"":_account.FULLNAME.ToString();
            txtJob.Text = _account.JOBTITLE==null?"":_account.JOBTITLE.ToString();
            var index = ddlcounttry.Items.FindByValue(_account.MAQG);
            ddlcounttry.SelectedIndex = ddlcounttry.Items.IndexOf(index);
            txtStreetAdress.Text = _account.CONTACTDDRESS==null?"":_account.CONTACTDDRESS.ToString();
            txtEmail.Text = _account.EMAIL==null?"":_account.EMAIL.ToString();
            txtphone.Text = _account.PHONE==null?"":_account.PHONE.ToString();
         
        }

        private void Loadreference()
        {
            CommonFunc.BindDropDownList(ddlcounttry, new QuocGiaDAO().GetList(), "TENQUOCGIA", "ID", true);
        }
        protected void btnsave_Click(object sender, EventArgs e)
        {
            ACOUNT _account = new AccountDAO().Get(Acount.USERNAME);
            _account.FULLNAME = String.IsNullOrEmpty(txtFullName.Text.Trim()) ? "" : txtFullName.Text.Trim();
            _account.JOBTITLE = String.IsNullOrEmpty(txtJob.Text.Trim()) ? "" : txtJob.Text.Trim();
            _account.CONTACTDDRESS = String.IsNullOrEmpty(txtStreetAdress.Text.Trim()) ? "" : txtStreetAdress.Text.Trim();
            _account.MAQG = ddlcounttry.SelectedValue.ToString();
            _account.EMAIL = String.IsNullOrEmpty(txtEmail.Text.Trim()) ? "" : txtEmail.Text.Trim();
            _account.PHONE = String.IsNullOrEmpty(txtphone.Text.Trim()) ? "" : txtphone.Text.Trim();

            if (new AccountDAO().UpdateAcountprofile(_account) == 1)
            {
                
                ShowInfor("Update Account Success!.");
                BindataToForm();
            }
            else
            {
                ShowError("Update Account Fail!.");
            }

        }
    }
}